#include "MyName.h"
using namespace std;

void main()
{
	long lsend;
	long lrecv;
	WSAData wsaData;
	WORD DLLVERSION;
	DLLVERSION = MAKEWORD(2, 1);
	lsend = WSAStartup(DLLVERSION, &wsaData);
	lrecv = WSAStartup(DLLVERSION, &wsaData);
	SOCKADDR_IN addr;
	int addrlen = sizeof(addr);

	SOCKET sConnect;
	SOCKET sListen;

	sConnect = socket(AF_INET, SOCK_STREAM, NULL); 
	addr.sin_addr.s_addr = inet_addr("127.0.0.1"); // local IP
	addr.sin_family = AF_INET;
	addr.sin_port = htons(1234);

	sListen = socket(AF_INET, SOCK_STREAM, NULL);
	bind(sListen, (SOCKADDR*) &addr, addrlen);
	listen(sListen, SOMAXCONN);

	
		cout << "Waiting for an incoming connection!" << endl;
		if (sConnect = accept(sListen, (SOCKADDR*) &addr, &addrlen))
		{

			cout << "A connect was found!" << endl;
			while (1)
			{
				char *msSend;
				char *msRecv;
				char *Temp;
				msRecv = new char[1024];
				msSend = new char[1024];
				string mss;
				cout << "Type something send to the F*in' Client: ";
				_flushall();
				gets_s(msSend, 1023);
				Temp = new char[strlen(msSend) + 1];
				strcpy_s(Temp, strlen(msSend) + 1, msSend);
				lsend = send(sConnect, Temp, strlen(Temp) + 1, NULL);
				delete []Temp;
				Temp = NULL;
				lrecv = recv(sConnect, msRecv, strlen(msRecv), NULL);
				cout << "The Fu*kin message from Client: ";

				puts(msRecv);

				delete []msRecv;
				msRecv = NULL;
				delete [] msSend;
				msSend = NULL;
			}
			
		}
	
}